<template>
	<view class="mainpadding beijingse">
		<view class="flexbetween mainpadding ffffff radius">
			<view class="ershib">持卡人</view>
			<input class="inputs textright" type="text" placeholder="请输入真实姓名" v-model="bank_realname">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">银行卡号</view>
			<input class="inputs textright" type="text" placeholder="请输入银行卡号" v-model="bank_cardno">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">开户行</view>
			<input class="inputs textright" type="text" placeholder="请输入开户行(具体到支行)" v-model="open_bank">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">开户行地址</view>
			<input class="inputs textright" type="text" placeholder="请输入开户行地址" v-model="bank_address">
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="qrbd">
			<view class="bigbtn">确认绑定</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				bank_realname: "", //持卡人
				bank_cardno: "", //银行卡号
				open_bank: "", //开户行
				bank_address: "", //开户行地址
			}
		},
		onLoad() {
			this.userinfor()
		},
		methods: {
			// 用户信息
			userinfor() {
				httpRequest.request('/api/user/index', 'POST', {
					// 传参
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.bank_address=res.data.user_bank.bank_address
						this.bank_cardno=res.data.user_bank.bank_cardno
						this.open_bank=res.data.user_bank.open_bank
						this.bank_realname=res.data.user_bank.bank_realname
					}
				})
			},
			qrbd(){
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.bank_realname == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
				
					return
				}
				if (this.bank_cardno == "") {
					uni.hideLoading()
					httpRequest.toast("请输入银行卡号")
					return
				}
				let pattern = /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/,
					str = this.bank_cardno.replace(/\s+/g, "");
				if (!pattern.test(str)) {
					httpRequest.toast("请输入正确银行卡号");
					return;
				}
				if (this.open_bank == "") {
					uni.hideLoading()
					httpRequest.toast("请输入开户行")
					return
				}
				if (this.bank_address == "") {
					uni.hideLoading()
					httpRequest.toast("请输入开户行地址")
					return
				}
				httpRequest.request('/api/user/addBank', 'POST', {
					// 传参
					bank_realname: this.bank_realname, //持卡人
					bank_cardno: this.bank_cardno, //银行卡号
					open_bank: this.open_bank, //开户行
					bank_address: this.bank_address, //开户行地址
				}, false, false, true).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.inputs {
		width: 60%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}
</style>
